'use strict';
const Service = require('egg').Service;
class TestService extends Service {
  async test1 (id) {
    return {
      id,
      name: 'xxx',
      age: 18,
    };
  }
  async testurl (data) {
    // const {ctx} = this;
    console.log('-------', data);
    const imglist = [];
    for (let i = 0; i < data.tempUrl.length; i++) {
      imglist.push(data.tempUrl[i].url);
    }
    console.log('urllist:', imglist.toString());
    const sqldata = [imglist.toString(), data.testdata];
    const sql = 'insert into users(name,username) values (?,?)';
    const res = await this.app.mysql.query(sql, sqldata);
    return res;
  }
  async geturl (data) {
    console.log('-------', data);
    // const username = data.username;
    // const password = data.password;
    const res = await this.app.mysql.query('select * from users where username=? ', ['1']);
    return res;
  }
  async posttest (data) {
    console.log('posttest:', data);
    const where = {
      where: {
        order_id: data.order_id,
      },
    };
    const res = await this.app.mysql.update('order1', { order_status: data.order_status }, where);
    return res;
  }
  async getnowdatatest (data) {
    console.log(data);
    // console.log(unix_timestamp(now())/1000);
    // const res = await this.app.mysql.update('order1', { order_status: data.order_status }, where);
    // const sql = 'select * from order1  ';
    // const sql = 'select * from order1 where YEAR(create_time)=YEAR(NOW());';
    // const start = date('Y-m-d 00:00:00');

    // const end = date('Y-m-d H:i:s');

    // const sql = `SELECT * FROM order1 WHERE create_time >= unix_timestamp( `start` ) AND create_time <= unix_timestamp( `end` )`

    const sql = 'select * from order1 where to_days(create_time) = to_days(now());';
    const res = await this.app.mysql.query(sql);

    return res;
  }
}
module.exports = TestService;
